var config = {};
var url = "https://www.zadker.com/api/";
var serverId;
var dkpServerId;
var dkpTaskStatus=1;
//var url = "http://8010dr731.zicp.vip/api/";
// var url = "https://118.195.189.224/api/";
var token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJtaW5pcHJvZ3JhbSIsImlzcyI6Inh5eiIsImV4cCI6MTY2Nzc4NzU0MCwiaWF0IjoxNjM2NjgzNTQwfQ.BYbhnc3M6EcYFb80fkK2ZHr31vtXWJzeWFLyV-QxC2A";
var res = http.get(url + "title/selectBySerialNumber?serialNumber=" + device.serial, {
    headers: {
        'token': token
    }
});
if (res.statusCode == 200) {
    var json = JSON.parse(res.body.string());
    if (json.code == "00000") {
        serverId = json.data.serverId;
        console.log(serverId + "头衔服务启动")
    }
}

var res2 = http.get(url + "stat/selectBySerialNumber?serialNumber=" + device.serial, {
    headers: {
        'token': token
    }
});
if (res2.statusCode == 200) {
    var json = JSON.parse(res2.body.string());
    if (json.code == "00000") {
        if(json.data){
            dkpServerId = json.data.serverId;
            console.log(dkpServerId + "DKP服务启动")
        }
    }
}


config.getConfig = function () {
    var res = http.get(url + "common/config", {
        headers: {
            'token': token
        }
    });
    if (res.statusCode == 200) {
        var json = JSON.parse(res.body.string());
        if (json.code == "00000") {
            return json.data;
        } else {
            return JSON.parse("{'snapshotInterval':'600000','jobCommandInterval':'600000'}");
        }
    }
};

config.getConfigByKey = function (key) {
    var res = http.get(url + "common/configByKey?key=" + key, {
        headers: {
            'token': token
        }
    });
    if (res.statusCode == 200) {
        var json = JSON.parse(res.body.string());
        if (json.code == "00000") {
            return json.data;
        }
    }
};

config.getTitleConfig = function () {
    var res = http.get(url + "title/selectTitleByServerId?serverId=" + serverId, {
        headers: {
            'token': token
        }
    });
    if (res.statusCode == 200) {
        var json = JSON.parse(res.body.string());
        if (json.code == "00000") {
            return json.data;
        }
    }
};

config.getUrl = function () {
    return url;
};
config.getToken = function () {
    return token;
};
config.getServerId = function () {
    return serverId;
};
config.getDkpServerId = function () {
    return dkpServerId;
};
config.getDkpTaskStatus = function () {
    return dkpTaskStatus;
};
config.setDkpTaskStatus = function (s) {
    dkpTaskStatus=s;
};
module.exports = config;